#ifndef TD_MOUSE_MANAGER_
#define TD_MOUSE_MANAGER_

/************************************************************************/
/* STL                                                                  */
/************************************************************************/
#include <map>

/************************************************************************/
/* SDL                                                                  */
/************************************************************************/
#include "SDL/SDL.h"

/************************************************************************/
/* Core                                                                */
/************************************************************************/
#include "Core/Utils.h"

/************************************************************************/
/* Resources                                                            */
/************************************************************************/
#include "Resources/ResourceManager.h"

/************************************************************************/
/* GUI                                                                  */
/************************************************************************/
#include "GUI/Panels/MarioInfoPanel.h"
#include "GUI/Panels/TowerInfoPanel.h"
#include "GUI/Panels/TowerMenuPanel.h"
#include "GUI/Panels/MenuPanel.h"
#include "GUI/Misc/Cursor.h"

/************************************************************************/
/* Game                                                                 */
/************************************************************************/
#include "Game/Screen.h"
#include "Game/Factories/AnimationSetFactory.h"
#include "Game/Tilemaps/TerrainTilemap.h"
#include "Game/Managers/TowerManager.h"
#include "Game/Managers/MarioManager.h"


/************************************************************************/
/* Wii                                                                  */
/************************************************************************/
#ifdef _WII
#include "wiiuse/wpad.h"
#endif

using namespace std;
using namespace TD_Core;
using namespace TD_Resources;

namespace TD_Game {
	
	
	class InputManager {
		
		Screen *m_pScreen;

		bool m_isTowerSelected;

		bool m_controlKeyDown;

	
		Coord2D m_terrainTilesize;
		TerrainTilemap *m_pTerrain;

		BaseMario *m_pSelectedCreep;
		unsigned int m_selectedCreepID;

		MarioInfoPanel *m_pCreepInfo;
		TowerInfoPanel *m_pTowerInfo;
		TowerMenuPanel *m_pTowerMenu;
		MenuPanel *m_pMenuPanel;

		towerTypes m_selectedTowerType;
		BaseTower * m_pSelectedTower;

		/** Buttons: */
		BaseButton *m_pStartButton;
		BaseButton *m_pMenuButton;


		/** Wii devices: */
		#ifdef _WII
		ir_t m_wiiIr;
		bool m_wiiMoteInitialized;
#endif
		Tile *m_pCursorTile;


		
		interaction_t processMouseOnSubElements(SDL_Event *event);
		interaction_t processMouse(SDL_Event *event);
		interaction_t processKeyboard(SDL_Event *event);
		

		inline bool isInsideCanvas(const Coord2D &position) { 
			if(position.x < (m_pScreen->getCanvasBounds().x - m_pScreen->getCanvasPosition().x) 
				&& position.y < (m_pScreen->getCanvasBounds().y - m_pScreen->getCanvasPosition().y) &&
				position.x > 0 && position.y > 0) {
					return true;
			}
			return false;
		}

	public:

		/************************************************************************/
		/* ctors and dtors					                                    */
		/************************************************************************/
		//Default constructor
		explicit InputManager();

		//Copy constructor
		explicit InputManager(const InputManager &rhs);

		//Assignment constructor
		InputManager& operator=(const InputManager &rhs);
		
		//Initialization constructor
		explicit InputManager(TerrainTilemap *g_pTerrain, TowerInfoPanel * g_pTowerInfo, 
								TowerMenuPanel * g_pTowerMenuPanel, MarioInfoPanel *g_pMarioInfoPanel, MenuPanel *g_pMenuPanel);
		
		//Destructor
		~InputManager();

		interaction_t process(Screen *g_pRenderScreen, unsigned int deltaTime);	

		/************************************************************************/
		/* Access functions                                                    */
		/************************************************************************/

		inline BaseMario * getSelectedCreep() {
			return(m_pSelectedCreep);	
		}
		inline unsigned int getSelectedCreepID() {
			return(m_selectedCreepID);
		}

		inline BaseTower * getSelectedTower() {
			return(m_pSelectedTower);
		}

		inline void resetSelection() {
			m_isTowerSelected = false;
		}

		inline bool getTowerSelection() const {
			return(m_isTowerSelected);
		}
		void render(SDL_Surface *const g_destSurface, unsigned int deltaTime);

	};
}

#endif